#pragma once

#include <linux/page.h>

extern int nr_free_pages;
extern unsigned long free_page_list;

extern unsigned long __get_free_page(int priority);

extern void free_page(unsigned long addr);

extern unsigned long paging_init(unsigned long start_mem, unsigned long end_mem);
extern void mem_init(unsigned long start_mem, unsigned long end_mem);

#define invalidate() \
    __asm__ __volatile__("movl %%cr3, %%eax\n\tmovl %%eax, %%cr3" \
                         : \
                         :)

extern unsigned long high_memory;

#define PAGE_OFFSET       ((unsigned long)0xC0000000)

#define __pa(x)           ((unsigned long)(x)-PAGE_OFFSET)
#define __va(x)           (((unsigned long)(x) + PAGE_OFFSET))

#define MAP_NR(addr)      (((addr)-PAGE_OFFSET) >> PAGE_SHIFT)
#define MAP_PAGE_RESERVED (1 << 15)

extern unsigned short *mem_map;

#define PAGE_PRESENT  0x001
#define PAGE_RW       0x002
#define PAGE_USER     0x004
#define PAGE_PWT      0x008 /* 486 only - not used currently */
#define PAGE_PCD      0x010 /* 486 only - not used currently */
#define PAGE_ACCESSED 0x020
#define PAGE_DIRTY    0x040
#define PAGE_COW      0x200 /* implemented in software (one of the AVL bits) */

#define PAGE_SHARED   (PAGE_PRESENT | PAGE_RW | PAGE_USER | PAGE_ACCESSED)
#define PAGE_TABLE    (PAGE_PRESENT | PAGE_RW | PAGE_USER | PAGE_ACCESSED)

#define PTRS_PER_PAGE (PAGE_SIZE / sizeof(void *))

#define GFP_BUFFER    0x00
#define GFP_ATOMIC    0x01
#define GFP_USER      0x02
#define GFP_KERNEL    0x03
